package com.corp.controller;

import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.corp.platform.common.response.RespResult;
import com.corp.two.spi.RemoteTwoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author Keanu
 * @Date 2020/7/2 0002 17:01
 * @Version
 **/
@RestController
public class RemoteTwoController implements RemoteTwoClient, EnvironmentAware {
    private Environment environment;
    @Autowired
    NacosConfigProperties nacosConfigProperties;

    @Override
    public RespResult<String> serviceTwo(LocalDateTime localDateTime) {
        String fileExtension = environment.resolvePlaceholders("${platform.nacos.share.file-extension:${spring.cloud.nacos.config.file-extension}}");
        System.out.println(environment.resolvePlaceholders(fileExtension));
        if (localDateTime == null) localDateTime = LocalDateTime.now();
        return RespResult.data(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(localDateTime));
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
}
